<?php

    // +----------------------------------------------------------------------
    // | 附件
    // +----------------------------------------------------------------------
    // | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
    // +----------------------------------------------------------------------
    // | Author: 微尘 <yicmf@qq.com>
    // +----------------------------------------------------------------------

    namespace app\controller\file\admin;

    use app\common\event\SystemConfig as SystemConfigEvent;
    use app\common\model\SystemConfig as SystemConfigModel;
    use app\model\file\Attachment as AttachmentModel;
    use yicmf\builder\Table;
    use think\facade\Url;
    use app\controller\admin\Common;

    class Attachment extends Common
    {
        protected function initialize()
        {
            parent::initialize();
        }

        public function _filter()
        {
        	return [];
        }

        public function index()
        {
            // 显示页面
            $builder = new Table();
            $builder->model(AttachmentModel::class)
				->where($this->_filter())
                ->order('id DESC')
                ->searchText('save_name', '附件名称', '附件名称')
                //         ->searchMoreTime('create_time', '时间：', ['pattern' => 'yyyy-MM-dd HH:mm:ss'])
                ->buttonCustom('file/admin/Attachment/setting', '附件设置')
//                ->buttonCustom('file/admin/Attachment/qiniu', '七牛设置')
                ->keyId()
                ->keyText('name', '附件名称')
                ->keyText('url', '保存路径')
                ->keyText('driver', '储存')
                ->keyTime('create_time', '创建时间')
                ->keyUser('user_id', '执行者')
                ->keyStatus()
                ->actionDelete( )
                ->actionRemove();
            return $builder->fetch();
        }

        /**
         * 附件
         */
        public function setting()
        {
            if ($this->request->isPost()) {
                $event = new SystemConfigEvent();
                $re = $event->updateValue($this->request->post(),$this->user);
                $this->_returnAuto($re,false);
            } else {
                $set = SystemConfigModel::where('status', 1)->where('group', 'upload_attachment')->where('is_dev',0)->order('sort ASC')->select();
               return SystemConfigEvent::builderView($set,'附件配置');
            }

        }

        /**
         * 七牛设置
         */
        public function qiniu()
        {
            if ($this->request->isPost()) {
                $event = new SystemConfigEvent();
                $re = $event->updateValue($this->request->post(),$this->user);
                $this->_returnAuto($re,false);
            } else {
                $set = SystemConfigModel::where('status', 1)->where('group', 'upload_driver')->where('is_dev',0)->order('sort ASC')->select();
               return SystemConfigEvent::builderView($set,'七牛配置');
            }

        }



    }
